package cn.donting.jme.edit.ui.inspector.imp.mat;

import cn.donting.jme.edit.attribute.Attribute;
import cn.donting.jme.edit.ex.AttributeLoader;
import cn.donting.jme.edit.ex.ExResourcesLoad;
import cn.donting.jme.edit.ex.InspectorUILoader;
import cn.donting.jme.edit.ui.inspector.AttributeInspectorUI;
import cn.donting.jme.edit.ui.inspector.InspectorUI;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * Material 的IAttributeLoader 兜底
 */
public class MaterialInspectorUILoader implements InspectorUILoader {

    @Override
    public List<InspectorUI> getInspectorUI(Spatial spatial) throws IOException {
        List<InspectorUI> inspectorUIS = new ArrayList<>();
        if (! (spatial instanceof Geometry))  return inspectorUIS;


        Geometry geometry=(Geometry) spatial;
        Material material = geometry.getMaterial();
        List<AttributeLoader> attributeLoaders = ExResourcesLoad.getAttributeLoaders(material);
        AttributeInspectorUI attributeInspectorUI=new AttributeInspectorUI("材质",null);
        inspectorUIS.add(attributeInspectorUI);
        for (AttributeLoader attributeLoader : attributeLoaders) {
            List<Attribute> attributes = attributeLoader.getAttribute(material);
            attributeInspectorUI.addAttribute(attributes);
        }

        return inspectorUIS;
    }
}
